#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;
using Agresso.Interface.Layer.Service;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class DADeskBankForm : Form
    {
        DaDeskBank m_bank;
        DADesk_PDA_Service m_daDeskService;
        UserControlDaDeskBankMapping m_parent;

        public DADeskBankForm(DaDeskBank bank, UserControlDaDeskBankMapping parent)
        {
            InitializeComponent();
            Text = bank.dadeskbank_id > 0 ? "Update Bank" : "Insert New Bank";
            m_daDeskService = new DADesk_PDA_Service();
            m_parent = parent;
            m_bank = bank;
            textBoxBankCode.Text = m_bank.bank_code;
            textBoxAgrDAType.Text = m_bank.da_type;
            textBoxAgrBizUnit.Text = m_bank.biz_unit;
            textBoxAccountCode.Text = m_bank.account_code;
        }

        private void button1OK_Click(object sender, EventArgs e)
        {
            if (textBoxBankCode.Text == "")
            {
                MessageBox.Show("Please fill Bank Code", "Verify");
                return;
            }
            updateVessel();
            this.Close();
        }

        private void updateVessel()
        {
          
            m_bank.bank_code = textBoxBankCode.Text;
            m_bank.da_type = textBoxAgrDAType.Text;
            m_bank.biz_unit = textBoxAgrBizUnit.Text;
            m_bank.account_code = textBoxAccountCode.Text;
            if (m_bank.dadeskbank_id > 0)
                m_daDeskService.UpdateBank(m_bank);
            else
                m_daDeskService.InsertBank(m_bank);
            m_parent.UpdateSelectedItem(m_bank);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonApply_Click(object sender, EventArgs e)
        {
            if (textBoxBankCode.Text == "")
            {
                MessageBox.Show("Please fill Bank Code", "Verify");
                return;
            }
            updateVessel();
            buttonApply.Enabled = false;
        }

        private void DADeskVesselForm_Load(object sender, EventArgs e)
        {
            textBoxBankCode.SelectAll();
            textBoxBankCode.Focus();
        }

        private void activate_apply(object sender, KeyPressEventArgs e)
        {
            buttonApply.Enabled = true;
        }
    }
}